<?php
class ClientTable extends CI_Controller{
	
	public function __construct(){
		parent::__construct();
		
		//check loggin
		if ($this->session->userdata('LoggedIn')){
			//load defense model
			$this->load->model('TableModel', 'table', TRUE);
		}else{
			$arr = array('status' => 'fail', 'message' => 'error message here 1');
			echo json_encode($arr);
			exit();
		}
	}
	
	public function all_table_detail(){
		$tables = $this->table->all_table();
		
		if ($tables == false) {
			$arr = array('status' => 'fail', 'message' => 'error message here 2');
			echo json_encode($arr);
			exit();
		}else {
			foreach ($tables as $table){
				if ($table->waiter_id == null){
					$table->waiter_id = 0;
				}
				if ($table->extra_table == null){
					$table->extra_table = 0;
				}
				
				if ($table->booking_status_id == null){
					$table->booking_status_id = 0;
				}
				
			}
			$arr = array('status' => 'success', 'info' => $tables);
			$json = json_encode($arr);
			print_r($json);
		}
	}
	
	public function table_detail(){
		if (!isset($_GET['id']) || empty($_GET['id'])){
			$arr = array('status' => 'fail', 'message' => 'error message here');
			echo json_encode($arr);
			exit();
		}
		
		$table_id = $_GET['id'];
		$table = $this->table->table_detail($table_id);
		
		if ($table == false){
			$arr = array('status' => 'fail', 'message' => 'error message here');
			echo json_encode($arr);
			exit();
		}else {
			$arr = array('status' => 'success', 'info' => $table);
			$json = json_encode($arr);
			print_r($json);
		}
	}
}